from google.appengine.ext import db
import xmw
class IllegalURL(db.Model):
    url = db.URLProperty()
    
class User(db.Model):
    user_id     =db.IntegerProperty(default=0)
    #user_id     =db.IntegerProperty(default=2)
    email    =db.EmailProperty()
    name   =db.StringProperty()
    created     =db.DateTimeProperty(auto_now_add=True)
    password    =db.StringProperty()
    def save(self):
        self.created = xmw.get_cn_now_time()
        self.put()

class XMW_Session_User(db.Model):
    user_id     = db.IntegerProperty()
    name    = db.StringProperty()
    email   =   db.EmailProperty()

#needed after login
class Login_Action(db.Model):
    #actural url will be:action?params
    #action=db.StringProperty()
    action     =db.StringProperty()
    params  =db.StringProperty()
    created     =db.DateTimeProperty(auto_now_add=True)

class Sub_Req_Status:
    INIT        ="INIT"
    """
        INIT  ---(send req to bot until got thread_id)-->IN_TRACE---(caculate sub users) 
        or
        bad
    """
    INIT        ="INIT"
    ACCEPTED    ="ACCEPTED"
    IN_TRACE    ="IN_TRACE"
    DELETE      ="DELETE"
    BAD         = "BAD"
    
class Sub_Req(db.Model):
    user_id        =db.IntegerProperty()
    title       =db.StringProperty()
    url         =   db.StringProperty()
    thread_id   =db.StringProperty()
    created     =db.DateTimeProperty()
    status      =db.StringProperty(default=Sub_Req_Status.INIT)
    #mailed      =db.BooleanProperty(default=False)
    sub_req_id  =db.StringProperty(default="NA",required=True)
    def save(self):
        if self.sub_req_id == "NA":
            self.sub_req_id=xmw.get_uuid_hex()
        self.put()

class Post_Task(db.Model):
    author=db.StringProperty()
    date=db.DateTimeProperty( )
    floor=db.StringProperty()
    content=db.TextProperty()    
    url=db.StringProperty()
    post_id     =db.StringProperty()
    thread_id   = db.StringProperty ()
    offset  =   db.IntegerProperty()
    
    
    seq         =db.IntegerProperty(default=0)
    lst_mail    =db.StringListProperty()
    title       =db.StringProperty()
